import random,string
import tkinter as tk
from pandas.io.common import is_url
from tkinter import messagebox

def game_word():
    with open("newn.txt","r") as nn:
        for i in range(5):
            this_word = random.choice(nn.read().split("\n"))
            if this_word:
                return list(this_word)
            else:
                pass

def check_right(user_word,raw_word,right_word):
    error_label : tk.Label
    user_word : list[list]
    right_word : list
    diminish = 0

    if len(user_word) != len(right_word) or not raw_word.isalpha():
        return diminish

    for i in range(len(right_word)):
        if user_word[i][0] != right_word[i]:
            if user_word[i][0] in right_word:
                diminish+=1
                user_word[i][1] = 1
            elif user_word[i][0] not in right_word:
                diminish+=2
                user_word[i][1] = 2
    if diminish == 0:
        return -1
    return diminish

def winner(root,letters):
    root:tk.Tk
    letters:list[tk.Label]
    temp = random.uniform(89.2,95.4)

    for letter in letters:
        letter.config(bg="gold")
    i = messagebox.showinfo("胜利",
                            f"恭喜您击败了全国{round(temp, 2)}%的玩家！！！"
                            , icon="info")
    root.quit()

def show_word(letters,words,settings,flag):
    words:list[list]
    letters:list[tk.Label]
    for i in range(len(words)):
        letters[i].config(text=words[i][0],)
        if flag == 0 and words[i][1]:
            letters[i].config(bg=settings.wrong_color[words[i][1]-1])


if __name__ == '__main__':
    pass






